package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.DetailBean;
import com.wnhz.work.jy.bean.IncomeAndExpensesBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by d on 2016/10/14.
 */
public class ExpensesFragmentAdapter extends BaseAdapter{
    private Context context;
    private List<IncomeAndExpensesBean.ExpendBean> detailList;

    public ExpensesFragmentAdapter(Context context, List<IncomeAndExpensesBean.ExpendBean> detailList) {
        this.context = context;
        this.detailList = detailList;
    }

    @Override
    public int getCount() {
        return detailList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DetailViewHolder viewHolder = new DetailViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.detail_item, null);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_money = (TextView) convertView.findViewById(R.id.tv_money);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (DetailViewHolder) convertView.getTag();
        }

        x.image().bind(viewHolder.iv_pic,detailList.get(position).getImg());
        viewHolder.tv_time.setText(detailList.get(position).getTime());
        viewHolder.tv_money.setText("¥"+detailList.get(position).getMoney());
        viewHolder.tv_type.setText(detailList.get(position).getType());

        return convertView;
    }

    class DetailViewHolder {
        TextView tv_time;
        ImageView iv_pic;
        TextView tv_type;
        TextView tv_money;
    }
}
